#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    map<int, vector<pair<int, int>>> mp;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    auto func1 = [&](int t, int l, int r) {
        int h = 0;
        for(int i = l; i <= r; i++) {
            while(1) {
                int x = (r - i) * (r - i) + (h + 1) * (h + 1);
                if(x > t * t) break;
                h++;
            }
            mp[i].push_back({- h, h});
        }
    };
    auto func2 = [&](int t, int l, int r) {
        int h = t;
        for(int i = l; i <= r; i++) {
            while(t) {
                int x = (i - l) * (i - l) + (h * h);
                if(x > t * t) h--;
                else break;
            }
            mp[i].push_back({-h, h});
        }
    };
    for(int i = 0; i < n; i++) {
        func1(b[i], a[i] - b[i], a[i]);
        func2(b[i], a[i], b[i] + a[i]);
    }
    int cnt = 0;
    for(auto& [k, arr] : mp) {
        sort(arr.begin(), arr.end());
        vector<pair<int, int>> ans;
        for (auto& p : arr) {
            if (!ans.empty() && p.first <= ans.back().second) { 
                ans.back().second = max(ans.back().second, p.second); 
            } else { 
                ans.emplace_back(p); 
            }
        }
        for(auto [l, r] : ans) {
            cnt += (r - l + 1);
        }
    }
    cout << cnt << endl;
}

signed main() {
    int t; cin >> t;
    while(t--) solve();
    return 0;
}